const db = require( '../db/db' );
const util = require( 'util' );

const tableName = 'core.account_confirm';

exports.updateConfirmed = async function ( key, confirmed ) {
    var sql = `UPDATE ${ tableName } SET confirmed=$1, updated_at=now() WHERE key=$2`;
    var params = [ confirmed, key ];

    try {

        var result = await db.runSql( sql, params );

        if ( result ) {
            return result.rows;
        }
        return null;

    } catch ( e ) {
        console.error( "更新邮箱确认信息出错", e );
        return null;
    }
};

exports.getByKey = async function ( key ) {
    var sql = `select * from ${ tableName } where key=$1 limit 1`;
    var params = [ key ];

    try {

        var result = await db.runSql( sql, params );

        if ( result ) {
            return result.rows;
        }
        return null;

    } catch ( e ) {
        console.error( "获取确认信息" );
        return null;
    }
};